import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Confirm from 'vux/src/components/confirm/index.vue'

export default {
  name: 'notice',
  components: {Confirm},
  data () {
    return {
      studentId: '',
      siteId: '',
      pageNo: 1,
      content: [],
      show: false
    }
  },
  mounted () {
    var _this = this
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.studentId = window.sessionStorage.getItem('studentId')
    if (_this.studentId == '-1') {
      _this.show = true
    } else {
      _this.gonotice()
    }
  },
  methods: {
    onCancel () {
      // 取消按钮
    },
    onConfirm () {
      // 确定按钮
      var _this = this
      _this.$router.push({path: '/login'})
    },
    gonotice () {
      var _this = this
      http.post(CONSTANT.NOTICELIST, {
        studentId: _this.studentId,
        siteId: _this.siteId,
        pageNo: _this.pageNo
      }, (res) => {
        console.log(res)
        if (res.content.length <= 0) {
          _this.pageNo--
          if (_this.pageNo <= 1) {
            _this.pageNo = 1
          }
        } else {
          if (_this.pageNo == 1) {
            _this.content = res.content
          } else {
            _this.content = _this.content.concat(res.content)
          }
        }
      })
    },
    lookMoreBtn () {
      var _this = this
      _this.pageNo++
      _this.gonotice()
    },
    gonoticeDetails (id) {
      window.sessionStorage.setItem('noticeId', id)
      this.$router.push({path: '/noticeDetails'})
    }
  }
}
